package com.liuweiheng.cloud.mq;

import com.liuweiheng.base.constant.mq.GlobalExchangeConstant;
import com.liuweiheng.base.constant.mq.GlobalQueueConstant;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * RabbitMq接收器 - Direct模式
 * @author lwh
 * @since 2021/5/31
 */
@Component
public class DirectReceiver {
    @RabbitListener(bindings = {
        @QueueBinding(
            value=@Queue,
            exchange=@Exchange(value= GlobalExchangeConstant.TEST_DIRECT, type= GlobalExchangeConstant.DIRECT),
            key = {GlobalQueueConstant.TEST_KEY}
        )
    })
    public void receive(Map message) {
        System.out.println("消费者接收到消息: [" + GlobalExchangeConstant.DIRECT + "模式 - "
                                               + GlobalExchangeConstant.TEST_DIRECT + "交换机 - "
                                               + GlobalQueueConstant.TEST_KEY + "路由 - "
                                               + message.toString()
                                               + "]"
        );
    }
}
